<template>
  <div id="hot-collections">
    <div class="col-box">
      <CollectionItem
        class="col-item"
        v-for="item in arrays.data"
        :colData="item"
        :key="item.id"
      />
    </div>
    <div class="pagination" v-if="arrays.count != 0">
      <el-pagination
        :page-size="pageSize"
        :pager-count="5"
        layout="prev, pager, next"
        :total="arrays.count"
        background
        @prev-click="prevPage"
        @next-click="nextPage"
        @current-change="pageChange"
      >
      </el-pagination>
    </div>
    <div class="no-result" v-if="arrays.count == 0">
      <span>什么都没找到</span>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import CollectionItem from "@/components/CollectionItem";
export default {
  name: "HotCollections",
  data() {
    return {
      pageIndex: 1,
      pageSize: 20,
    };
  },
   components: {
    CollectionItem,
  },
  mounted() {
    this.$store.dispatch("hotCollections", {
      pageIndex: this.pageIndex.toString(),
      pageSize: this.pageSize.toString(),
    });
  },
  computed: {
    ...mapState({
      arrays: (store) => store.hot.hotCollections,
    }),
  },
  methods: {
    // 上一页
    prevPage() {
      this.pageIndex = this.pageIndex - 1;
      this.$store.dispatch("arrays", {
        pageIndex: this.pageIndex.toString(),
        pageSize: this.pageSize.toString(),
      });
    },
    // 下一页
    nextPage() {
      this.pageIndex = this.pageIndex + 1;
      this.$store.dispatch("arrays", {
        pageIndex: this.pageIndex.toString(),
        pageSize: this.pageSize.toString(),
      });
    },

    // 页数改变
    pageChange(page) {
      this.pageIndex = page.toString();
      this.$store.dispatch("arrays", {
        pageIndex: page.toString(),
        pageSize: this.pageSize.toString(),
      });
    },
  },
};
</script>

<style>
</style>